package cn.donting.jme.swing.drag;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;

public class DataTransferable implements Transferable {
    private final DataFlavor[] dataFlavors;
    private final Object data;
    public DataTransferable(Object data,DataFlavor... dataFlavors) {
        this.dataFlavors=dataFlavors;
        this.data=data;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return dataFlavors;
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        for (DataFlavor dataFlavor : dataFlavors) {
            if (dataFlavor.getMimeType().equals(flavor.getMimeType())) {
                return true;
            }
        }
        return false;
    }

    @Override
    public Object getTransferData(DataFlavor flavor) {
        return data;
    }
}
